package com.graduation.smartparkingplatform.ServiceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.graduation.smartparkingplatform.Dao.VisitorMapper;
import com.graduation.smartparkingplatform.Pojo.VisitorList;
import com.graduation.smartparkingplatform.Service.VisitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VisitorServiceImpl implements VisitorService {
  @Autowired VisitorMapper visitorMapper;

  // 获取访客记录列表（分页）
  @Override
  public PageInfo<VisitorList> getVisitorList(Integer page, Integer count) {
    PageHelper.startPage(page, count);

    List<VisitorList> getVisitorList = visitorMapper.getVisitorList();

    PageInfo<VisitorList> pageInfo = new PageInfo<>(getVisitorList);

    return pageInfo;
  }

  // 模糊搜索访客记录（分页）
  @Override
  public PageInfo<VisitorList> searchVisitor(
      Integer page, Integer count, String userName, String ip) {
    PageHelper.startPage(page, count);

    List<VisitorList> VisitorList = visitorMapper.searchVisitor(userName, ip);

    PageInfo<com.graduation.smartparkingplatform.Pojo.VisitorList> pageInfo =
        new PageInfo<>(VisitorList);

    return pageInfo;
  }

  // 删除访客记录
  @Override
  public Boolean deleteVisitor(Integer visitorId) {
    return visitorMapper.deleteVisitor(visitorId);
  }

  // 获取所有访客记录
  @Override
  public List<VisitorList> getVisitorListAll() {
    return visitorMapper.getVisitorListAll();
  }
}
